function [ xint yint zint, zinterr] = surfBestData(population)
%SURFDATA Returns the data necesarry to do a surf plot.
%   patterns: invariant data (in a 3d function: (x,y))
%   finalWeights: neural network trained weights

global patterns solutions;

[value index] = max(population.fitness);
warray = population.individuals{index};

finalWeights{1} = reshape( warray(1:60) , 20 , 3 );
finalWeights{2} = reshape( warray(61:480) , 20 , 21 );
finalWeights{3} = reshape( warray(481:501) , 1 , 21 );




x = patterns(1,:)';
y = patterns(2,:)';
z = zeros(1, length(x));

xmin = min(x); xmax = max(x);
ymin = min(y); ymax = max(y);
gridres = 50;

for i=1:length(x)
    z(i) = valPattern(finalWeights, [x(i) ; y(i)]);
end

xv = linspace(xmin, xmax, gridres);
yv = linspace(ymin, ymax, gridres);
[xint, yint] = meshgrid(xv,yv);
zint = griddata(x,y,z,xint,yint);
zerr = solutions;
zinterr = griddata(x,y,abs(zerr-z), xint, yint);

surf(xint, yint, zint);

end

